//
//  ForwardDetailsViewController.m
//  ioschishan
//
//  Created by 马田成 on 2017/7/31.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ForwardDetailsViewController.h"
#import "HomePicDetailsOneTableViewCell.h"
#import "HomePicDetailTwoTableViewCell.h"
#import "ForwardDetailTableViewCell.h"
#import "HomePicDetailFourCell.h"
#import "HomePicDetailPingView.h"
#import "HomePicDetailFootTableViewCell.h"
#import "HomePicForwardViewController.h"
#import "RemarksCellHeightModel.h"
@interface ForwardDetailsViewController ()<UITableViewDelegate, UITableViewDataSource,CAAnimationDelegate,HomePicDetailTwoDelegate>
{
    BOOL _isShow; // 是否展开
    NSString *_cellContentStr; // 备注消息
    UIView *grayView;
    
}


@property (nonatomic, strong) UITextView *commentTextView;
@property (nonatomic, strong) UILabel *placeHolderLabel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *viewOfFoot;

@property (nonatomic, strong) NSMutableDictionary *dataDic;
@property (nonatomic, strong) NSMutableArray *arrMu;//图片数组
@property (nonatomic, strong) NSMutableArray *upPic;
@property (nonatomic, strong) NSMutableArray *CommentArr;
@property (nonatomic, strong) HomePicDetailPingView *sectionWork;


@end

@implementation ForwardDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"动态详情"];
    [self creationViewOne];
    [self creationView];
    [self regeditCell];
    
    [self loadDataSource];
    
    
    
    // Do any additional setup after loading the view.
}
- (void)creationViewOne{
    UIView *threadView = [[UIView alloc]initWithFrame:CGRectMake(0, screenScale(1), scrWidth(), screenScale(0.7))];
    threadView.backgroundColor = getColor(@"cccccc");
    [self.view addSubview:threadView];
    
    self.viewOfFoot = [[UIView alloc] init];
    [self.view addSubview:self.viewOfFoot];
    self.viewOfFoot.backgroundColor = [UIColor whiteColor];
    [self.viewOfFoot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(44);
        make.bottom.equalTo(self.view);
        
    }];
    
    self.commentTextView = [[UITextView alloc] init];
    [self.viewOfFoot addSubview:self.commentTextView];
    self.commentTextView.layer.borderWidth = 1.0f;
    self.commentTextView.layer.borderColor =getColor(@"e3e3e3").CGColor;
    self.commentTextView.layer.cornerRadius = 2;
    self.commentTextView.layer.masksToBounds = YES;
    
    self.commentTextView.font = [UIFont systemFontOfSize:13];
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewOfFoot).with.offset(5);
        make.left.equalTo(self.viewOfFoot).with.offset(0);
        make.right.equalTo(self.viewOfFoot).with.offset(-50);
        make.bottom.equalTo(self.viewOfFoot).with.offset(0);
        
    }];
    
    
    self.placeHolderLabel = [[UILabel alloc] init];
    
    self.placeHolderLabel.numberOfLines = 0;
    self.placeHolderLabel.font = [UIFont systemFontOfSize:13];
    self.placeHolderLabel.text = @"发表评论";
    self.placeHolderLabel.textColor = getColor(@"b6b6b6");
    [self.placeHolderLabel sizeToFit];
    [self.commentTextView addSubview:self.placeHolderLabel];
    
    
    [self.commentTextView setValue:self.placeHolderLabel forKey:@"_placeholderLabel"];
    
    UIButton *buttonOfSend = [[UIButton alloc] init];
    [self.viewOfFoot addSubview:buttonOfSend];
    [buttonOfSend setTitle:@"发送" forState:UIControlStateNormal];
    buttonOfSend.titleLabel.font = [UIFont systemFontOfSize:11];
    buttonOfSend.backgroundColor = getColor(@"3A95FF");
    [buttonOfSend setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonOfSend mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.viewOfFoot.mas_centerY);
        make.right.equalTo(self.viewOfFoot).with.offset(-5);
        make.top.equalTo(self.viewOfFoot).with.offset(5);
        make.width.offset(40);
        
    }];
    [buttonOfSend addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    
}

- (void)creationView{
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 - 50);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    //    self.tableView.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 200;
    [self.view addSubview:self.tableView];
    
    
    //右边item
    UIButton *searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, screenScale(40), screenScale(40))];
    [searchBtn setImage:[UIImage imageNamed:@"more_icon"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(pianoBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];
    self.navigationItem.rightBarButtonItem = rightItme;
    
    
    
}

- (void)regeditCell{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HomePicDetailsOneTableViewCell" bundle:nil] forCellReuseIdentifier:@"HomePicDetailsOneTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"ForwardDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"ForwardDetailTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"HomePicDetailFootTableViewCell" bundle:nil] forCellReuseIdentifier:@"HomePicDetailFootTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HomePicDetailPingView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"HomePicDetailPingView"];
    
}

- (NSMutableArray *)photoDeleSource{
    if (!_arrMu) {
        _arrMu = [NSMutableArray array];
    }
    return  _arrMu;
}
- (NSMutableArray *)photoupPic{
    if (!_upPic) {
        _upPic = [NSMutableArray array];
    }
    return  _upPic;
}
- (NSMutableArray *)CommentArr{
    if (!_CommentArr) {
        _CommentArr = [NSMutableArray array];
    }
    return  _CommentArr;
}
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
#pragma mark - ---------- Section的内容 ----------
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 1) {
        self.sectionWork = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HomePicDetailPingView"];
        
        return self.sectionWork;
        
    }
    return self.sectionWork;
    
    
}
#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 65;
    }else {
        
        return 0;
        
    }
}
//section 不随tableView滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.tableView)
        
    {
        
        CGFloat sectionHeaderHeight = 65; //header高度
        
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
        
    }
    
    
    
}


#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 4;
        
    }else {
        
        return  5;
        
    }
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
            return 61;
            
        }else if (indexPath.row == 1){
            
            return [RemarksCellHeightModel cellHeightWith:_cellContentStr andIsShow:_isShow andLableWidth:BOUNDS.size.width-30 andFont:12 andDefaultHeight:52 andFixedHeight:42 andIsShowBtn:8] - 12;
            
        }else if (indexPath.row == 2){
            
            return 253;
            
        }else {
            
            return 113;
            
        }
    }else {
        
        return UITableViewAutomaticDimension;
        
    }
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
            HomePicDetailsOneTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HomePicDetailsOneTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            return cell;
        }else if (indexPath.row == 1){
            
            static NSString *cellName = @"HomePicDetailTwoTableViewCell";
            HomePicDetailTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
            if (!cell) {
                cell = [[HomePicDetailTwoTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellName];
                cell.delegate = self;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            [cell setCellContent:_cellContentStr andIsShow:_isShow  andCellIndexPath:indexPath];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
            return cell;
            
        }else if (indexPath.row == 2){
            ForwardDetailTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ForwardDetailTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            return cell;
            
            
        }else {
            
            HomePicDetailFourCell *cell=(HomePicDetailFourCell *)[tableView dequeueReusableCellWithIdentifier:@"HomePicDetailFourCell"];
            if (cell == nil) {
                cell=[[HomePicDetailFourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomePicDetailFourCell"];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            
            [cell.buttonFen addTarget:self action:@selector(ForwardClick) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
            
        }
    }else {
        
        HomePicDetailFootTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HomePicDetailFootTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
}



#pragma mark -- Dalegate
- (void)remarksCellShowContrntWithDic:(NSDictionary *)dic andCellIndexPath:(NSIndexPath *)indexPath
{
    _isShow = [[NSString stringWithFormat:@"%@",[dic objectForKey:@"isShow"]] boolValue];
    
    [_tableView reloadData];
}


- (void)loadDataSource {
    _cellContentStr = @"而服务就开个房hi未公开差距是过节费嘎达是骄傲的很据是否故意给五分与我共分为与恢复噶啥可减肥哈萨克较高的更好看的撒娇规范和骄傲是快递费工商局和开发干烧。阿斯蒂芬阿斯蒂芬asdf发送大手动阀是的发送到发大师傅鞍山打算大声道发啊请问千万人阿道夫阿斯蒂芬啊地方234第三方韩国 的复合弓好地方和豆腐干好发动过好地方规划对方过后";
}
//右边
- (void)pianoBtnClick{
    
    grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    grayView.backgroundColor = [UIColor colorWithRed:0 / 255.0f green:0 / 255.0f blue:0 / 255.0f alpha:0.2];
    
    [[UIApplication sharedApplication].keyWindow addSubview:grayView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
    [grayView addGestureRecognizer:tapGesture];
    
    UIView *viewWhite = [[UIView alloc] init];
    [grayView addSubview:viewWhite];
    viewWhite.backgroundColor = [UIColor whiteColor];
    [viewWhite mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(grayView);
        make.right.equalTo(grayView);
        make.bottom.equalTo(grayView);
        make.height.offset(270);
        
    }];
    //微信
    UIButton *buttonWeiXin = [[UIButton alloc] init];
    [grayView addSubview:buttonWeiXin];
    [buttonWeiXin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(24);
        make.left.equalTo(viewWhite).with.offset(27);
        make.height.offset(32);
        make.width.offset(40);
        
    }];
    
    [buttonWeiXin setBackgroundImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
    UILabel *labelWeiXin = [[UILabel alloc] init];
    [grayView addSubview:labelWeiXin];
    labelWeiXin.text = @"微信";
    labelWeiXin.font = [UIFont systemFontOfSize:12];
    [labelWeiXin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(72);
        make.centerX.equalTo(buttonWeiXin.mas_centerX);
        make.height.offset(17);
        
    }];
    labelWeiXin.textColor = getColor(@"9B9B9B");
    
    //朋友圈
    
    UIButton *buttonFriend = [[UIButton alloc] init];
    [grayView addSubview:buttonFriend];
    [buttonFriend mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(21);
        make.left.equalTo(buttonWeiXin.mas_right).with.offset((DEF_SCREEN_WIDTH - 54 - 160)/ 3 );
        make.height.offset(40);
        make.width.offset(40);
        
    }];
    
    [buttonFriend setBackgroundImage:[UIImage imageNamed:@"pengyouquan"] forState:UIControlStateNormal];
    UILabel *labelFriend  = [[UILabel alloc] init];
    [grayView addSubview:labelFriend];
    labelFriend.text = @"朋友圈";
    labelFriend.font = [UIFont systemFontOfSize:12];
    [labelFriend mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(72);
        make.centerX.equalTo(buttonFriend.mas_centerX);
        make.height.offset(17);
        
    }];
    labelFriend.textColor = getColor(@"9B9B9B");

    
    //QQ
    
    UIButton *buttonQQ = [[UIButton alloc] init];
    [grayView addSubview:buttonQQ];
    [buttonQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(22);
        make.left.equalTo(buttonFriend.mas_right).with.offset((DEF_SCREEN_WIDTH - 54 - 160)/ 3 );
        make.height.offset(38);
        make.width.offset(36);
        
    }];
    
    [buttonQQ setBackgroundImage:[UIImage imageNamed:@"qq"] forState:UIControlStateNormal];
    UILabel *labelQQ  = [[UILabel alloc] init];
    [grayView addSubview:labelQQ];
    labelQQ.text = @"QQ";
    labelQQ.font = [UIFont systemFontOfSize:12];
    [labelQQ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(72);
        make.centerX.equalTo(buttonQQ.mas_centerX);
        make.height.offset(17);
        
    }];
    labelQQ.textColor = getColor(@"9B9B9B");

    //qq空间
    
    UIButton *buttonQQSpace = [[UIButton alloc] init];
    [grayView addSubview:buttonQQSpace];
    [buttonQQSpace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(20);
        make.left.equalTo(buttonQQ.mas_right).with.offset((DEF_SCREEN_WIDTH - 54 - 160)/ 3 );
        make.height.offset(38);
        make.width.offset(41);
        
    }];
    
    [buttonQQSpace setBackgroundImage:[UIImage imageNamed:@"qzone"] forState:UIControlStateNormal];
    UILabel *labelQQSpace  = [[UILabel alloc] init];
    [grayView addSubview:labelQQSpace];
    labelQQSpace.text = @"QQ空间";
    labelQQSpace.font = [UIFont systemFontOfSize:12];
    [labelQQSpace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewWhite).with.offset(72);
        make.centerX.equalTo(buttonQQSpace.mas_centerX);
        make.height.offset(17);
        
    }];
    labelQQSpace.textColor = getColor(@"9B9B9B");

    UIView *oneView = [[UIView alloc] init];
    [viewWhite addSubview:oneView];
    oneView.backgroundColor = getColor(@"CCCCCC");
    [oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(viewWhite).with.offset(15);
        make.right.equalTo(viewWhite).with.offset(-15);
        make.height.offset(1);
        make.top.equalTo(labelQQSpace.mas_bottom).with.offset(20);
        
    }];
    
    //收藏
    
    UIButton *buttonCollect = [[UIButton alloc] init];
    [grayView addSubview:buttonCollect];
    [buttonCollect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(oneView.mas_bottom).with.offset(24);
        make.centerX.equalTo(buttonWeiXin.mas_centerX);
        make.height.offset(48);
        make.width.offset(48);
        
    }];
    
    [buttonCollect setBackgroundImage:[UIImage imageNamed:@"collect"] forState:UIControlStateNormal];
    UILabel *labelCollect  = [[UILabel alloc] init];
    [grayView addSubview:labelCollect];
    labelCollect.text = @"收藏";
    labelCollect.font = [UIFont systemFontOfSize:12];
    [labelCollect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(oneView.mas_bottom).with.offset(72);
        make.centerX.equalTo(buttonCollect.mas_centerX);
        make.height.offset(17);
        
    }];
    labelCollect.textColor = getColor(@"9B9B9B");

    
    UIView *twoView = [[UIView alloc] init];
    [viewWhite addSubview:twoView];
    twoView.backgroundColor = getColor(@"CCCCCC");
    [twoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(viewWhite);
        make.right.equalTo(viewWhite);
        make.height.offset(1);
        make.top.equalTo(labelCollect.mas_bottom).with.offset(20);
        
    }];
    
    UIButton *buttonCancel = [[UIButton alloc] init];
    [viewWhite addSubview:buttonCancel];
    [buttonCancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(viewWhite);
        make.right.equalTo(viewWhite);
        make.bottom.equalTo(viewWhite);
        make.top.equalTo(twoView.mas_bottom).with.offset(1);
        
    }];
    [buttonCancel setTitle:@"取消" forState:UIControlStateNormal];
    
    buttonCancel.titleLabel.font = [UIFont systemFontOfSize:16];
    buttonCancel.backgroundColor = [UIColor whiteColor];
    [buttonCancel setTitleColor:getColor(@"4A4A4A") forState:UIControlStateNormal];
    
    [buttonCancel addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    

}

- (void)dismissContactView {
    
    [grayView removeFromSuperview];
}
//发送
- (void)commentClick{
    
}
//转发
- (void)ForwardClick{
    HomePicForwardViewController *vc= [[HomePicForwardViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
